package com.business.web.spring;


import java.util.List;
import org.apache.log4j.Logger;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.business.domain.T_task_node_instance;
import com.easyworkflow.web.spring.WorkFlowController;

//import com.workflow.WorkFlowUtils;
import com.common.db.JsonVO;
import com.common.db.Pg;
import com.common.utils.BeanUtils;
import com.business.domain.T_contract_release;
//import com.business.mapper.T_contract_releaseMapper;
import com.business.service.T_contract_releaseService;

@Controller
@RequestMapping("/t_contract_release")

public class T_contract_releaseController extends WorkFlowController{

	private static Logger log = Logger.getLogger(T_contract_releaseController.class.getName());

	@Resource
    private T_contract_releaseService t_contract_releaseService;

	//@Autowired
	//private WorkFlowUtils workFlowUtils;

	//@Resource
	//private T_contract_releaseMapper mapper;
	//private int id;
	//private int[] ids;
	private Pg pg;

	/**
	 * 1、获取 T_contract_release信息列表，并且在列表页面展示
	 * @param request
	 * @return Pg，json格式
	 */
	@RequestMapping("/getAllT_contract_release")
	@ResponseBody
	public Pg getAllT_contract_release(HttpServletRequest request){
        int pageSize = 10;
        int startIndex = 0;
        T_contract_release t_contract_release = new T_contract_release();
        try{
	        if(request.getParameter("pageSize")!=null){
	        	pageSize = BeanUtils.stringToInt("pageSizeFlag", request.getParameter("pageSize"));
	        }
	        if(request.getParameter("startIndex")!=null){
	            startIndex = BeanUtils.stringToInt("startIndexFlag", request.getParameter("startIndex"));
	        }
	        if(request.getParameter("process_code")!=null){ //取得动作流 流程英文名称，后台查询数据关联使用
	        	t_contract_release.setProcess_code(request.getParameter("process_code"));
	        }
			if(request.getParameter("contractno")!=null&&!"".equals(request.getParameter("contractno"))){
	        	t_contract_release.setContractno(request.getParameter("contractno"));
	        }
			if(request.getParameter("buildingno")!=null&&!"".equals(request.getParameter("buildingno"))){
	        	t_contract_release.setBuildingno(request.getParameter("buildingno"));
	        }
			if(request.getParameter("conpanyno")!=null&&!"".equals(request.getParameter("conpanyno"))){
	        	t_contract_release.setConpanyno(request.getParameter("conpanyno"));
	        }
			if(request.getParameter("releaser")!=null&&!"".equals(request.getParameter("releaser"))){
	        	t_contract_release.setReleaser(request.getParameter("releaser"));
	        }
			if(request.getParameter("releasearea")!=null&&!"".equals(request.getParameter("releasearea"))){
	        	t_contract_release.setReleasearea(request.getParameter("releasearea"));
	        }
			if(request.getParameter("creater")!=null&&!"".equals(request.getParameter("creater"))){
	        	t_contract_release.setCreater(request.getParameter("creater"));
	        }
			if(request.getParameter("creattime")!=null&&!"".equals(request.getParameter("creattime"))){
	        	t_contract_release.setCreattime(request.getParameter("creattime"));
	        }
			if(request.getParameter("updater")!=null&&!"".equals(request.getParameter("updater"))){
	        	t_contract_release.setUpdater(request.getParameter("updater"));
	        }
			if(request.getParameter("updatetime")!=null&&!"".equals(request.getParameter("updatetime"))){
	        	t_contract_release.setUpdatetime(request.getParameter("updatetime"));
	        }
			if(request.getParameter("billtype")!=null&&!"".equals(request.getParameter("billtype"))){
	        	t_contract_release.setBilltype(request.getParameter("billtype"));
	        }
			if(request.getParameter("sftype")!=null&&!"".equals(request.getParameter("sftype"))){
	        	t_contract_release.setSftype(request.getParameter("sftype"));
	        }
			if(request.getParameter("releasetime")!=null&&!"".equals(request.getParameter("releasetime"))){
	        	t_contract_release.setReleasetime(request.getParameter("releasetime"));
	        }
			if(request.getParameter("ext1")!=null&&!"".equals(request.getParameter("ext1"))){
	        	t_contract_release.setExt1(request.getParameter("ext1"));
	        }
			if(request.getParameter("ext2")!=null&&!"".equals(request.getParameter("ext2"))){
	        	t_contract_release.setExt2(request.getParameter("ext2"));
	        }
			if(request.getParameter("ext3")!=null&&!"".equals(request.getParameter("ext3"))){
	        	t_contract_release.setExt3(request.getParameter("ext3"));
	        }
			if(request.getParameter("ext4")!=null&&!"".equals(request.getParameter("ext4"))){
	        	t_contract_release.setExt4(request.getParameter("ext4"));
	        }
			if(request.getParameter("ext5")!=null&&!"".equals(request.getParameter("ext5"))){
	        	t_contract_release.setExt5(request.getParameter("ext5"));
	        }
			if(request.getParameter("ext6")!=null&&!"".equals(request.getParameter("ext6"))){
	        	t_contract_release.setExt6(request.getParameter("ext6"));
	        }
			if(request.getParameter("status")!=null&&!"".equals(request.getParameter("status"))){
	        	t_contract_release.setStatus(request.getParameter("status"));
	        }
			if(request.getParameter("billstartdate")!=null&&!"".equals(request.getParameter("billstartdate"))){
	        	t_contract_release.setBillstartdate(request.getParameter("billstartdate"));
	        }
			if(request.getParameter("billenddate")!=null&&!"".equals(request.getParameter("billenddate"))){
	        	t_contract_release.setBillenddate(request.getParameter("billenddate"));
	        }
			if(request.getParameter("reason")!=null&&!"".equals(request.getParameter("reason"))){
	        	t_contract_release.setReason(request.getParameter("reason"));
	        }
			if(request.getParameter("imagepath")!=null&&!"".equals(request.getParameter("imagepath"))){
	        	t_contract_release.setImagepath(request.getParameter("imagepath"));
	        }
			if(request.getParameter("biztype")!=null&&!"".equals(request.getParameter("biztype"))){
	        	t_contract_release.setBiztype(request.getParameter("biztype"));
	        }
      	    if(request.getParameter("releaseid")!=null&&!"".equals(request.getParameter("releaseid"))){
	        	t_contract_release.setReleaseid(new Integer(request.getParameter("releaseid")));
	        }

	        if(request.getParameter("startdate")!=null&&!"".equals(request.getParameter("startdate"))){
	        	t_contract_release.setStartdate(request.getParameter("startdate"));
	        }
	        if(request.getParameter("enddate")!=null&&!"".equals(request.getParameter("enddate"))){
	        	t_contract_release.setEnddate(request.getParameter("enddate"));
	        }
	        t_contract_release.setStartNo( startIndex );
	        t_contract_release.setPageSize( pageSize );
	        t_contract_release.setEndNo( pageSize );
	    	List<T_contract_release> findAll = t_contract_releaseService.findAll(t_contract_release);
	        int totalCount = t_contract_releaseService.findCountAll(t_contract_release);
	       	pg = new Pg(findAll, totalCount, pageSize, startIndex);
	       	request.setAttribute("t_contract_releaseList", findAll);
		    request.setAttribute("pg", pg);
	    } catch (Exception e) {
			e.printStackTrace();
			log.error("------query t_contract_releaseList error:"+e);
		}

		return pg;
	}

	/**
	 * 2、新增保存  T_contract_release信息并且返回成功或者失败信息json格式结果如：result:[success/error]
	 * @param t_contract_release
	 * @param request
	 * @return
	 */
	@RequestMapping("/saveT_contract_release")
	@ResponseBody
	public JsonVO saveT_contract_release(T_contract_release t_contract_release, HttpServletRequest request,HttpServletResponse response){
		JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);
		//如果有特殊需求，需要将json对象值转成java实体对象属性值
		if(t_contract_releaseService.save(t_contract_release)>0){
	        vo.setResult("success");
	        vo.setJieguo(true);
		}
		return vo;
	}

	/**
	 * 3。1、修改T_contract_release信息并且返回成功或者失败信息json格式结果如：result:[success/error]
	 * @param t_contract_release
	 * @param request
	 * @return JsonVO
	 */
	@RequestMapping("/updateT_contract_release")
	@ResponseBody
	public JsonVO updateT_contract_release(T_contract_release t_contract_release, HttpServletRequest request){
		JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);
		//如果有特殊值需要处理，在此处手工转换
		//T_contract_release t_contract_releaseTemp = t_contract_releaseService.findById(t_contract_release);
		//t_contract_releaseTemp.setXXX(t_contract_release.getXXX());
		//if(t_contract_releaseService.update(t_contract_releaseTemp)){

		if(t_contract_releaseService.update(t_contract_release)>0){
	        vo.setResult("success");
	        vo.setJieguo(true);
		}
		return vo;
	}

    /**
     * 3。2、提交审核业务数据
     * 修改T_contract_release信息并且返回成功或者失败信息json格式结果如：result:[success/error]
     * @param t_contract_release
     * @param request
     * @return JsonVO
     */
    @RequestMapping("/tjshT_contract_release")
    @ResponseBody
    public JsonVO tjshT_company(T_contract_release t_contract_release, HttpServletRequest request) {
        //启动工作流； 请假流程；
        return startMyTask( getTaskIdByBiztype(t_contract_release.getBiztype()),t_contract_release.getBiztype(), t_contract_release.getReleaseid(), request);
    }

    /**
     * 3.3、提交T_contract_release审核通过，并且返回成功或者失败信息json格式结果如：result:[success/error]
     * @param t_task_node_instance
     * @param request
     * @return JsonVO
     */
    @RequestMapping("/shtgT_contract_release")
    @ResponseBody
    public JsonVO shtgT_contract_release(T_task_node_instance t_task_node_instance, HttpServletRequest request) {
        return doMyAgree(t_task_node_instance.getTninstanceid(), t_task_node_instance.getNote(), request);
    }

    /**
     * 3.4、提交T_contract_release审核退回，信息并且返回成功或者失败信息json格式结果如：result:[success/error]
     * @param t_task_node_instance
     * @param request
     * @return JsonVO
     */
    @RequestMapping("/shthT_contract_release")
    @ResponseBody
    public JsonVO shthT_contract_release(T_task_node_instance t_task_node_instance, HttpServletRequest request) {
        return doMyBack(t_task_node_instance.getTninstanceid(), t_task_node_instance.getNote(), request);
    }
    
	/**
	 * 4、根据id查询T_contract_release单个信息并显示在修改页面
	 * @param id
	 * @param request
	 * @return T_contract_release json格式字符串
	 */
	@RequestMapping("/getT_contract_release")
	@ResponseBody
	public T_contract_release getT_contract_release(Integer id,HttpServletRequest request){
		T_contract_release t_contract_release = new T_contract_release();
		t_contract_release.setReleaseid(id);
		return t_contract_releaseService.findById(t_contract_release);
	}

	/**
	 * 5、删除T_contract_release根据id
	 * @param id
	 * @param request
	 * @param response
	 * return JsonVO ：json格式字符串
	 */
	@RequestMapping("/delT_contract_release")
	@ResponseBody
	public JsonVO delT_contract_release(Integer id,HttpServletRequest request,HttpServletResponse response){
        JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);

		T_contract_release t_contract_release = new T_contract_release();
		t_contract_release.setReleaseid(id);

		if(t_contract_releaseService.delete(t_contract_release)>0){
			vo.setResult("success");
	        vo.setJieguo(true);
		}
		return vo;
	}

	/**
	 * 6、跳转到t_contract_release/toT_contract_releaseList查询所有数据页面
	 *  return /WEB-INF/views/business/t_contract_release/t_contract_releaseList.jsp
	 */
    @RequestMapping(value = "/toT_contract_releaseList")
    public String toT_contract_releaseList() {
    	log.debug("------跳转到/WEB-INF/views/business/t_contract_release/t_contract_releaseList.jsp------");
        return "business/t_contract_release/t_contract_releaseList";
    }

	/**
	 * 7、新增、修改、详情页面t_contract_release/toT_contract_releaseCurd跳转
     * business/t_contract_release/T_contract_releaseCurd.jsp
	 */
    @RequestMapping(value = "/toT_contract_releaseCurd")
    public String toT_contract_releaseCurd() {
    	log.debug("------跳转到/WEB-INF/views/business/t_contract_release/t_contract_releaseCurd.jsp------");
        return "business/t_contract_release/t_contract_releaseCurd";
    }

    /**
	 * 8、批量删除T_contract_release根据主键id
	 * 是否要实现批量删除，待考虑，基本上用途不大
	 * @param id
	 * @param request
	 * @param response
	@RequestMapping("/delT_contract_releaseBatch")
	public String delT_contract_releaseBatch(HttpServletRequest request,HttpServletResponse response){
		String[] ids = request.getParameterValues("ids");
		System.out.println("------ids="+ids);
		T_contract_release t_contract_release = new T_contract_release();
		int j=0;
		for(int i =0;i< ids.length;i++){
			j++;
			log.error("------ids[i]="+ids[i]);
			t_contract_release.setReleaseid(new Integer(ids[i]).intValue());
			t_contract_releaseService.delete(t_contract_release);
		}
		if(j==ids.length){
			log.debug("------t_contract_release批量删除成功！------");
		}else{
			log.error("------t_contract_release批量删除部分成功！部分失败！------");
		}

		return "redirect:/t_contract_release/getAllT_contract_release";
	}
*/



}









